﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Leave_Request_Form.aspx.cs"
    Inherits="Trig_AMJ_HR_Forms.Layouts.Trig_AMJ_HR_Forms.Leave_Request_Form" DynamicMasterPageFile="~masterurl/default.master" %>

<%-- <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
--%>
<%@ Register TagPrefix="trig" TagName="userInfo" Src="~/_controltemplates/Trig_AMJ_IT_Forms/UserProfileInfo.ascx" %>
<%@ Register TagPrefix="trig" TagName="LeaveComments" Src="~/_controltemplates/Trig_AMJ_AMG_Forms/TrigAMJFormsComments/TrigAMJFormsCommentsUserControl.ascx" %>
<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel="Stylesheet" type="text/css" href="/_layouts/1033/STYLES/Themable/FORMS.CSS" />
    <link rel="Stylesheet" type="text/css" href="/Style Library/Al Majed/CSS/Trig_HR.css" />
    <script language="javascript" src="/_layouts/Scripts/validation.js" type="text/javascript"></script>
    <style type="text/css">
        #s4-leftpanel
        {
            display: none;
        }
        .s4-ca
        {
            margin-left: 0px;
        }
        .ms-validations
        {
            color: Red;
        }
        .style2
        {
            width: 373px;
        }
        .style3
        {
            width: 366px;
        }
        body, td, th
        {
            font-size: 8pt;
            font-family: Verdana, Arial, sans-serif;
        }
    </style>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <%--<SharePoint:FormDigest ID="FormDigest1" runat="server" />--%>
    <asp:Panel ID="pnlFullForm" runat="server" CssClass="pnlAMFform">
        <table class="tbl-main">
            <tr>
                <td colspan="4" class="formtitle">
                    Leave Request Form
                </td>
            </tr>
            <tr>
                <td colspan="4" class="Note-td">
                    <asp:Label ID="lblnote1" runat="server" Text="Some notes will be come here!!!" CssClass="Notes-msg"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="1">
                    Reference No :
                </td>
                <td colspan="2">
                    <asp:Label ID="lblLevReqNo" runat="server" Text="Reference number will be generated upon save"
                        Font-Bold="True" Font-Size="XX-Small" CssClass="ms-long ms-spellcheck-true" ForeColor="Red"></asp:Label>
                </td>
                <td align="right" rowspan="2" class="UserInfo-Sec-td">
                    <trig:userInfo runat="server" ID="userInfo" Visible="true" />
                </td>
            </tr>
            <tr>
                <td colspan="1">
                    Date of filling :
                </td>
                <td colspan="2">
                    <SharePoint:DateTimeControl ID="dtpDate" runat="server" DateOnly="true" IsRequiredField="true"
                        LocaleId="2057" Enabled="false" ErrorMessage="Please specify the date" />
                </td>
            </tr>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Leave Information
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <asp:Panel ID="pnlSec" runat="server">
                        <table width="907" cellpadding="0" cellspacing="0">
                            <tr>
                                <td rowspan="4" colspan="1" width="264" valign="top" style="padding: 6px">
                                    <asp:RadioButtonList ID="rdBtn" AutoPostBack="true" runat="server" OnSelectedIndexChanged="rdBtn_SelectedIndexChanged"
                                        RepeatDirection="Horizontal" RepeatLayout="Flow">
                                        <asp:ListItem Text="Logged in User" Value="0" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="On Behalf of" Value="1"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                                <td colspan="3">
                                    Leave Type :
                                </td>
                                <td width="364">
                                    <asp:RadioButtonList runat="server" ID="rdBtnLeaveType" RepeatDirection="Horizontal"
                                        OnSelectedIndexChanged="rdBtnLeaveType_SelectedIndexChanged" AutoPostBack="true">
                                        <asp:ListItem Text="Annual" Value="0" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="Emergency" Value="1"></asp:ListItem>
                                        <asp:ListItem Text="Others" Value="2"></asp:ListItem>
                                    </asp:RadioButtonList>
                                    <div id="divLeaveOth" runat="server" style="padding-left: 22px" visible="false">
                                        <span title="This is a required field." class="ms-validations"><strong>*</strong></span>
                                        <asp:TextBox runat="server" ID="txtLeaveOthers" Width="304px" align="right"></asp:TextBox>
                                    </div>
                                </td>
                            </tr>
                            <tr runat="server" id="f" visible="false">
                                <td colspan="3">
                                    Eligible for vacation :
                                </td>
                                <td colspan="3">
                                    <asp:RadioButtonList runat="server" ID="rdBtnEligible" RepeatDirection="Horizontal">
                                        <asp:ListItem Text="Yes" Value="0" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="1"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    Airticket borne by employee :
                                </td>
                                <td colspan="3">
                                    <asp:RadioButtonList runat="server" ID="rdBtnAirTkt" RepeatDirection="Horizontal">
                                        <asp:ListItem Text="Yes" Value="0" Selected="True"></asp:ListItem>
                                        <asp:ListItem Text="No" Value="1"></asp:ListItem>
                                    </asp:RadioButtonList>
                                </td>
                            </tr>
                        </table>
                    </asp:Panel>
                </td>
            </tr>
            <asp:UpdatePanel runat="server" ID="uptReqEmp">
                <ContentTemplate>
                    <asp:Panel ID="pnlReqEmpInf" runat="server" Visible="false">
                        <tr>
                            <td class="tdHeadingTextLeftAlign" colspan="4">
                                Requested Employee Information
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Name :<span title="This is a required field." class="ms-validations"><strong>*</strong></span>
                            </td>
                            <td>
                                <SharePoint:PeopleEditor ID="pplReqUser" runat="server" MultiSelect="false" AutoPostBack="true"
                                    Width="250px" />
                                <asp:TextBox ID="txtReqUser" runat="server" ReadOnly="true" Width="250px" Visible="false"
                                    Enabled="false"></asp:TextBox>
                            </td>
                            <td>
                                Employee ID :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqEmpId" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Division :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqDivision" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                            </td>
                            <td>
                                Department :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqDepartment" runat="server" Width="250px" ReadOnly="true"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Designation :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqDesignation" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                            </td>
                            <td>
                                Mobile Number :
                            </td>
                            <td>
                                <asp:TextBox ID="txtReqMobileNo" runat="server" Width="250px" onkeypress="return isNumberKey(this)"></asp:TextBox>
                            </td>
                            <td colspan="2">
                            </td>
                        </tr>
                    </asp:Panel>
                </ContentTemplate>
                <Triggers>
                    <asp:PostBackTrigger ControlID="rdBtn" />
                </Triggers>
            </asp:UpdatePanel>
            <tr>
                <td class="tdHeadingTextLeftAlign" colspan="4">
                    Employment
                </td>
            </tr>
            <tr>
                <td>
                    Date of Employment :
                </td>
                <td>
                    <asp:TextBox ID="txtDOJ" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
                <td>
                    No.of years employed :
                </td>
                <td>
                    <asp:TextBox ID="txtExpYear" runat="server" Width="125px" ReadOnly="true"></asp:TextBox><span>
                        yy:mm</span>
                </td>
            </tr>
            <tr>
                <td>
                    Passport Number :
                </td>
                <td>
                    <asp:TextBox ID="txtPassNo" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
                <td>
                    Passport Expiry :
                </td>
                <td>
                    <asp:TextBox ID="txtPassExpire" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Qatar ID Number :
                </td>
                <td>
                    <asp:TextBox ID="txtQatariID" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
                <td>
                    Qatar ID Expiry :
                </td>
                <td>
                    <asp:TextBox ID="txtQatarIDExpire" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Nationality :
                </td>
                <td>
                    <asp:TextBox ID="txtNationality" runat="server" ReadOnly="true" Width="250px"></asp:TextBox>
                </td>
                <td colspan="2">
                </td>
            </tr>
            <tr>
                <td class="tdHeadingTextLeftAlign" colspan="4">
                    Vacation Details
                </td>
            </tr>
            <tr>
                <td>
                    Travel Date : <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <SharePoint:DateTimeControl runat="server" ID="dtTravelDt" DateOnly="true" LocaleId="2057" />
                    <%--<asp:TextBox ID="txtTravelDt" runat="server" ReadOnly="true" Width="250px" Visible="false"></asp:TextBox>--%>
                    <asp:Label runat="server" ID="lblTravelDt" Width="250px" Font-Bold="true" Font-Size="X-Small"
                        ForeColor="Red"></asp:Label>
                </td>
                <td>
                    Return Date: <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td>
                    <SharePoint:DateTimeControl runat="server" ID="dtReturnDt" DateOnly="true" LocaleId="2057" />
                    <%-- <asp:TextBox ID="txtReturnDt" runat="server" ReadOnly="true" Width="250px" Visible="false"></asp:TextBox>--%>
                    <asp:Label runat="server" ID="lblReturnDt" Width="250px" Font-Bold="true" Font-Size="X-Small"
                        ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    No. of days :
                </td>
                <td>
                    <asp:HiddenField runat="server" ID="hdnBalanceLeave" />
                    <asp:HiddenField runat="server" ID="txtLeaveDay" />
                    <asp:TextBox ID="txtLeaveDays" runat="server" ReadOnly="true" Width="250px" Enabled="false"
                        EnableViewState="true"></asp:TextBox>
                </td>
                <td id="tdWodlbl" runat="server" visible="false">
                    Work Endorsed to : <span title="This is a required field." class="ms-validations"><strong>
                        *</strong></span>
                </td>
                <td id="tdWodText" runat="server" visible="false">
                    <SharePoint:PeopleEditor ID="pplWorkEodTo" runat="server" MultiSelect="false" AutoPostBack="true"
                        Width="250px" />
                    <asp:TextBox runat="server" ID="txtWorkEodTo" ReadOnly="true" Visible="false"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="tdHeadingTextLeftAlign" colspan="4">
                    Vacation History
                </td>
            </tr>
            <tr runat="server" id="trVacationDetails" visible="false">
                <td colspan="4" align="center">
                    <asp:Label runat="server" ID="lblVacationDetails" Text="" Font-Size="X-Small" ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <asp:Panel ID="pnlgvVacations" runat="server" align="center">
                <tr>
                    <td colspan="4">
                        <asp:GridView ID="gvVacationDetails" runat="server" AutoGenerateColumns="false" CssClass="Grid-default"
                            AlternatingRowStyle-CssClass="alt-tr">
                            <Columns>
                                <asp:TemplateField HeaderText="S.No" ItemStyle-CssClass="td-center" HeaderStyle-CssClass="td-center">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="txtSNo" Text='<%# Container.DataItemIndex+1 %>' ReadOnly="true"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Travel Date" ItemStyle-CssClass="td-center" HeaderStyle-CssClass="td-center">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="txtLeaveDt" Text='<%# Eval("RequestDate", "{0:dd/MM/yyyy}") %>'
                                            ReadOnly="true"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Leave Type" ItemStyle-CssClass="td-center" HeaderStyle-CssClass="td-center">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="txtLeaveType" Text='<%# Bind("LeaveType") %>' ReadOnly="true"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Resumption Date" ItemStyle-CssClass="td-center" HeaderStyle-CssClass="td-center">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="txtResumptionDt" Text='<%# Eval("ResumptionDate", "{0:dd/MM/yyyy}") %>'
                                            ReadOnly="true"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Ticket Paid By" ItemStyle-CssClass="td-center" HeaderStyle-CssClass="td-center">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="txtTicketPaidBy" Text='<%# Bind("TicketPaidBy") %>'
                                            ReadOnly="true"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>
                    </td>
                </tr>
            </asp:Panel>
            <tr>
                <td colspan="4" class="tdHeadingTextLeftAlign">
                    Comments / Workflow Area
                </td>
            </tr>
            <tr>
                <td colspan="4" style="padding: 10px;">
                    <trig:LeaveComments ID="leaveComments" runat="server" />
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <table width="100%" cellpadding="0" cellspacing="0" class="Section-Approver">
                        <asp:Panel ID="pnlCommentArea" runat="server" class="Section-Approver">
                            <tr>
                                <td colspan="4" class="AppHeading">
                                    <strong>Comments</strong><span class="ms-validations" title="This is a required field."><strong>
                                        *</strong></span>
                                </td>
                            </tr>
                            <tr>
                                <td width="150px">
                                    <asp:Image ID="ImgUser" runat="server" Height="50px" Width="50px" />
                                    <br />
                                    <asp:Label ID="LblCommentsUserName" runat="server" Font-Bold="True" Font-Size="XX-Small"
                                        ForeColor="#003399" Text=""></asp:Label>
                                </td>
                                <td colspan="3">
                                    <asp:TextBox ID="TxtComments" runat="server" TextMode="MultiLine" Width="600px"></asp:TextBox>
                                </td>
                            </tr>
                            <tr id="upAtt" runat="server">
                                <td width="150px">
                                    Upload Attachment
                                </td>
                                <td colspan="3">
                                    <asp:FileUpload ID="upfile" runat="server" CssClass="ms-fileinput" Width="250px" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel ID="pnlForward" runat="server" Visible="false">
                            <tr>
                                <td colspan="4" style="text-align: left; background-color: #121e66; color: #ffffff;
                                    font-weight: bold; padding: 10px;">
                                    <table cellpadding="0" cellspacing="0">
                                        <tr>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbSendBack" runat="server" Text="Send Back" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnSendBackUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbSendBack" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForwardOthers" runat="server" Text="Forward to other user"
                                                            AutoPostBack="true" GroupName="Users" onclick="javascript:fnForwardUsers(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForwardOthers" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                            <td>
                                                <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                                    <ContentTemplate>
                                                        <asp:RadioButton ID="rtbForward" runat="server" Text="Forward" GroupName="Users"
                                                            AutoPostBack="true" onclick="javascript:fnForword(this)" />
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="rtbForward" EventName="CheckedChanged" />
                                                    </Triggers>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="3">
                                                <asp:UpdatePanel ID="UpdatePanel4" runat="server">
                                                    <ContentTemplate>
                                                        <asp:Label ID="lblWFStaticUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                        <asp:Label ID="lblSendBacktoUser" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow" Visible="false"></asp:Label>
                                                        <asp:Label ID="lblsendBackUserValue" runat="server" Text="" Font-Bold="True" Font-Size="XX-Small"
                                                            ForeColor="Yellow"></asp:Label>
                                                    </ContentTemplate>
                                                </asp:UpdatePanel>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                            <tr style="padding: 10px; display: none" id="trotherUsers">
                                <td style="padding: 10px; font-weight: bold; color: #121e66;" width="130px">
                                    User Name :
                                </td>
                                <td style="padding: 10px;" colspan="3">
                                    <asp:Label ID="lblCNTSectionMsg" runat="server" Text=""></asp:Label>
                                    <SharePoint:PeopleEditor ID="pplcnt" runat="server" MultiSelect="false" AllowEmpty="false"
                                        Width="250px" ForeColor="Red" AutoPostBack="false" />
                                </td>
                            </tr>
                        </asp:Panel>
                        <asp:Panel runat="server" ID="btnCntrls">
                            <tr>
                                <td colspan="4">
                                    <asp:UpdatePanel ID="UpdatePanel5" runat="server">
                                        <ContentTemplate>
                                            <asp:Label ID="lblError" runat="server" CssClass="error-msg" Text=""></asp:Label>
                                        </ContentTemplate>
                                    </asp:UpdatePanel>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="4" class="tblButtons" style="padding-top: 5px;">
                                    <asp:Button ID="btnSubmit" runat="server" CssClass="btn-Submit" Text="Submit" OnClientClick="javascript:return fnValidation();" />
                                    <asp:Button ID="btnApprove" runat="server" CssClass="btn-Approver" Text="Approve"
                                        OnClientClick="javascript:return fnValidationApprove();" Visible="false" />
                                    <asp:Button ID="btnReject" runat="server" CssClass="btn-Reject" Text="Reject" Visible="false"
                                        OnClientClick="javascript:return fnValidationReject();" />
                                    <input id="btnCancel" class="btn-Cancel" type="button" value="Close" accesskey="C"
                                        onclick="window.parent.history.back()" runat="server" />
                                </td>
                            </tr>
                        </asp:Panel>
                    </table>
                </td>
            </tr>
            <asp:Panel ID="pnlView" runat="server" Visible="false">
                <tr>
                    <td colspan="4" style="text-align: center;">
                        <input id="btnViewClose" class="btn-Cancel" type="button" onclick="window.parent.history.back()"
                            value="Close" accesskey="C" />
                    </td>
                </tr>
            </asp:Panel>
        </table>
    </asp:Panel>
    <asp:Panel ID="pnlAccessDenied" runat="server" Visible="false" CssClass="pnlAMFform">
        <table cellpadding="0" cellspacing="0" width="65%">
            <tr>
                <td style="text-align: center;">
                    <asp:Label ID="lblAccessDeniedMsg" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                    <asp:Label ID="lblUserNotvailable" runat="server" Text="" Font-Size="Medium" ForeColor="Red"
                        Font-Bold="True" Visible="false"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px;">
                    <asp:Image ID="Image1" runat="server" ImageUrl="~/_layouts/1033/IMAGES/IRForm/AccessDeniedImage.png" />
                </td>
            </tr>
            <tr>
                <td style="text-align: center; padding-top: 10px">
                    <input id="butonclose" class="ms-ButtonHeightWidth" type="button" onclick="window.parent.history.back()"
                        value="Close" accesskey="C" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <asp:HiddenField ID="hdnWfOrder" runat="server" Value="" />
    <asp:Panel ID="pnlAlert" runat="server">
    </asp:Panel>
    <script language="javascript" type="text/javascript">
        var siteUrl = '/sites/forms/';

        function retrieveAllUsersAllGroups() {

            var clientContext = new SP.ClientContext(siteUrl);
            this.collGroup = clientContext.get_web().get_siteGroups();
            web = clientContext.get_web();
            clientContext.load(web);
            clientContext.load(collGroup);
            clientContext.load(collGroup, 'Include(Users)');

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }

        function onQuerySucceeded() {

            var userInfo = '';

            var groupEnumerator = collGroup.getEnumerator();
            while (groupEnumerator.moveNext()) {
                var oGroup = groupEnumerator.get_current();
                if (group.get_title() == "AMJ Admins") {
                    var collUser = oGroup.get_users();
                    var userEnumerator = collUser.getEnumerator();
                    while (userEnumerator.moveNext()) {
                        var oUser = userEnumerator.get_current();
                        this.userInfo += '\nGroup ID: ' + oGroup.get_id() +
                '\nGroup Title: ' + oGroup.get_title() +
                '\nUser: ' + oUser.get_title() +
                '\nLogin Name: ' + oUser.get_loginName();
                    }
                }
            }

            alert(userInfo);
        }

        function onQueryFailed(sender, args) {

            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
       
    </script>
    <script language="javascript" type="text/javascript">

        document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
        document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
        var element2;

        element2 = document.getElementById('<%= txtLeaveOthers.ClientID %>');

        var Empinfopnl = document.getElementById('<%= pnlReqEmpInf.ClientID %>');
        if (Empinfopnl != null) {
            Empinfopnl.style.display = 'none';
        }

        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }

        function fnOthEnable() {

            var MyRadio = document.getElementById("<%=rdBtnLeaveType.ClientID%>");
            var options = MyRadio.getElementsByTagName("input");
            var radVal;
            for (x = 0; x < options.length; ++x) {
                if (options[x].checked) {
                    radVal = x;
                    alert(radVal);
                }
            }
            if (radVal == 2) {
                alert('block');
                element2.style.display = "none";
            }
        }

        function fnOnBehalf(obj) {
            debugger;
            var onBehalf = document.getElementById("<%=rdBtn.ClientID%>");
            var cntrls = document.getElementById('<%=pnlReqEmpInf.ClientID%>');
            var options = onBehalf.getElementsByTagName("input");
            var radVal;
            for (x = 0; x < options.length; ++x) {
                if (options[x].checked) {
                    radVal = 1;
                    break;
                }
            }
            if (radVal == 1)
                cntrls.style.display = 'none';
            else
                cntrls.style.display = 'block';

        }

        function fnForwardUsers(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "inline";
            else
                document.getElementById("trotherUsers").style.display = "none";

        }

        function fnSendBackUsers(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "none";
        }
        function fnForword(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "none";
        }
    
    </script>
    <script language="javascript" type="text/javascript">


        function ckDates() {

            document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
            document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            debugger;

            var travelDts = false;
            var returnDts = false;
            var weodDts = false;
            var rval = true;

            Trim(document.getElementById('<%= dtpDate.ClientID  %>'));
            Trim(document.getElementById('<%= dtTravelDt.ClientID  %>'));
            Trim(document.getElementById('<%= dtReturnDt.ClientID  %>'));
            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));
            Trim(document.getElementById('<%= lblTravelDt.ClientID  %>'));
            Trim(document.getElementById('<%= lblReturnDt.ClientID  %>'));
            Trim(document.getElementById('<%= txtLeaveDays.ClientID  %>'));
            Trim(document.getElementById('<%= hdnWfOrder.ClientID  %>'));
            Trim(document.getElementById('<%= hdnBalanceLeave.ClientID  %>'));

            var travelDt = document.getElementById('<%= dtTravelDt.Controls[0].ClientID %>');
            var reqDt = document.getElementById('<%= dtpDate.Controls[0].ClientID %>');
            var returnDt = document.getElementById('<%= dtReturnDt.Controls[0].ClientID %>');
            var LeaveDays = document.getElementById('<%= txtLeaveDays.ClientID %>');
            var Comments = document.getElementById('<%= TxtComments.ClientID %>');

            var hdnWfOrder = document.getElementById('<%= hdnWfOrder.ClientID %>');

            var hdnBalLeave = document.getElementById('<%= hdnBalanceLeave.ClientID %>');

            var TravelDate = document.getElementById('<%= lblTravelDt.ClientID %>');
            TravelDate.innerText = "";
            var ReturnDate = document.getElementById('<%= lblReturnDt.ClientID %>');
            ReturnDate.innerText = "";

            if (isEmpty(travelDt)) {
                TravelDate.innerText = "Fields marked with (*) cannot be left blank";
                objFocus = travelDt;
                rval = false;
            }

            else {
                if (!IsValidDateFormat(travelDt.value)) {
                    TravelDate.innerText = "Date format should be dd/mm/yyyy !";
                    objFocus = travelDt;
                    rval = false;
                }
                else {

                    if (!PreSaveAction(reqDt, travelDt)) {
                        TravelDate.innerText = "The Travel Date should be greater than the Current Date";
                        objFocus = travelDt;
                        rval = false;
                    }
                    else {
                        travelDts = true;
                        TravelDate.innerText = "";
                    }
                }
            }

            if (travelDts) {

                if (isEmpty(returnDt)) {
                    ReturnDate.innerText = "Fields marked with (*) cannot be left blank";
                    objFocus = returnDt;
                    rval = false;
                }

                else {
                    if (!IsValidDateFormat(returnDt.value)) {
                        ReturnDate.innerText = "Date format should be dd/mm/yyyy !";
                        objFocus = returnDt;
                        rval = false;
                    }
                    else {

                        calculateDays();
                    }
                }
            }

            function calculateDays() {
                if (travelDts == true) {
                    if (!PreSaveAction(travelDt, returnDt)) {
                        ReturnDate.innerText = "The Return Date should be greater than the Travel Date";
                        LeaveDays.value = "";
                        objFocus = returnDt;
                    }
                    else {
                        returnDts = true;
                        ReturnDate.innerText = "";
                        DaysCalculation(returnDt, travelDt, LeaveDays);

                        var item1 = parseInt(hdnBalLeave.value);
                        var item2 = parseInt(LeaveDays.value);
                        if (!isEmpty(hdnBalLeave)) {
                            if (item2 > item1) {
                                ReturnDate.innerText = "You do not have a required balance Leave";
                                objFocus = returnDt;
                            }
                        }
                        else {
                            ReturnDate.innerText = "You do not have a required balance Leave";
                            objFocus = returnDt;
                        }
                    }
                }
            }
            if (rval == false) {
                objFocus.focus();
            }

        }

    </script>
    <script language="javascript" type="text/javascript">

        document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
        document.getElementById('<%= lblError.ClientID  %>').style.display = "none";


        var obj = document.getElementById('<%= rtbForwardOthers.ClientID%>');
        if (obj.checked == true)
            document.getElementById("trotherUsers").style.display = "inline";
        else
            document.getElementById("trotherUsers").style.display = "none";

        function fnForwardUsers(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "inline";
            else
                document.getElementById("trotherUsers").style.display = "none";

        }

        function fnSendBackUsers(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "none";
        }
        function fnForword(obj) {
            if (obj.checked == true)
                document.getElementById("trotherUsers").style.display = "none";
        }

        function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }


        function Trim(TrimString) {
            var tempObj;
            if (TrimString) { tempObj = TrimString; TrimString = tempObj.value; }
            if (TrimString == "undefined" || TrimString == null) return null;
            if (TrimString.length == 0) TrimString = "";
            else {
                var Lcont = 0, TempStrArray = TrimString.split(" "), Rcont = TempStrArray.length - 1;
                while (TempStrArray[Lcont] == "") Lcont++; while (TempStrArray[Rcont] == "") Rcont--;
                if (Rcont < Lcont) TrimString = ""; else
                    for (TrimString = TempStrArray[Lcont], Lcont++; Lcont <= Rcont; Lcont++) TrimString += " " + TempStrArray[Lcont];
                var re = /\'|/g;
                TrimString = TrimString.replace(re, "");
            }
            if (tempObj && TrimString != "undefined" && TrimString != null)
            { tempObj.value = TrimString; return tempObj }
            else return TrimString;
        }

        function getParameterByName(name) {
            name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
            var regexS = "[\\?&]" + name + "=([^&#]*)";
            var regex = new RegExp(regexS);
            var results = regex.exec(window.location.search);
            if (results == null)
                return "";
            else
                return decodeURIComponent(results[1].replace(/\+/g, " "));
        }

        function DaysCalculate() {
            Trim(document.getElementById('<%= txtLeaveDays.ClientID  %>'));
            Trim(document.getElementById('<%= dtTravelDt.ClientID  %>'));
            Trim(document.getElementById('<%= dtReturnDt.ClientID  %>'));
            Trim(document.getElementById('<%= hdnBalanceLeave.ClientID  %>'));

            var travelDt = document.getElementById('<%= dtTravelDt.Controls[0].ClientID %>');
            var returnDt = document.getElementById('<%= dtReturnDt.Controls[0].ClientID %>');
            var leaveDays = document.getElementById('<%= txtLeaveDays.ClientID %>');

            DaysCalculation(returnDt, travelDt, leaveDays);

            var leaveDay = document.getElementById('<%= txtLeaveDay.ClientID %>');
            leaveDay.value = leaveDays.value;

        }

        function fnValidationApprove() {

            debugger;
            document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));
            Trim(document.getElementById('<%= hdnWfOrder.ClientID  %>'));

            var hdnWfOrder = document.getElementById('<%= hdnWfOrder.ClientID %>');

            var weodTo = document.getElementById('<%=pplWorkEodTo.ClientID %>');

            var rval = true;
            var ErrorMsg = "";
            var objFocus;

            if (document.getElementById('<%= TxtComments.ClientID  %>').value == "") {
                ErrorMsg = "Fields marked with (*) cannot be left blank";
                objFocus = document.getElementById('<%= TxtComments.ClientID  %>');
                rval = false;
            }

            if (hdnWfOrder.value == "Supervisor") {

                if (isEmpty(weodTo)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = weodTo;
                    rval = false;
                }

            }


            if (rval == false) {
                document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                objFocus.focus();
            }

            else {
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            }
            return rval;
        }


        function fnValidationReject() {

            debugger;
            document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));
            Trim(document.getElementById('<%= hdnWfOrder.ClientID  %>'));

            var hdnWfOrder = document.getElementById('<%= hdnWfOrder.ClientID %>');

            var weodTo = document.getElementById('<%=pplWorkEodTo.ClientID %>');

            var rval = true;
            var ErrorMsg = "";
            var objFocus;

            if (document.getElementById('<%= TxtComments.ClientID  %>').value == "") {
                ErrorMsg = "Fields marked with (*) cannot be left blank";
                objFocus = document.getElementById('<%= TxtComments.ClientID  %>');
                rval = false;
            }

            if (rval == false) {
                document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                objFocus.focus();
            }

            else {
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            }
            return rval;
        }


        function fnLeaveOther() {

            var MyRadio = document.getElementById("<%=rdBtnLeaveType.ClientID%>");
            var options = MyRadio.getElementsByTagName("input");
            var radVal;
            for (x = 0; x < options.length; ++x) {
                if (options[x].checked) {
                    radVal = x;

                }
            }
            if (radVal == 2) {

                if (isEmpty(document.getElementById("<%=txtLeaveOthers.ClientID%>")))
                    return true;
                else
                    return false;

            }
            else {
                return false
            }
        }


        function fnValidation() {
            var isDateEmpty = false;
            debugger;
            var querystringval = getParameterByName('Mode');
            document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
            var rval = true;
            var ErrorMsg = "";
            var objFocus;
            var travelDts = false;
            var returnDts = false;
            var weodDts = false;
            var leaveOK = true;

            Trim(document.getElementById('<%= rdBtn.ClientID  %>'));
            Trim(document.getElementById('<%= TxtComments.ClientID  %>'));

            Trim(document.getElementById('<%= dtpDate.ClientID  %>'));
            Trim(document.getElementById('<%= dtTravelDt.ClientID  %>'));
            Trim(document.getElementById('<%= dtReturnDt.ClientID  %>'));
            Trim(document.getElementById('<%= pplWorkEodTo.ClientID  %>'));
            Trim(document.getElementById('<%= hdnWfOrder.ClientID  %>'));
            Trim(document.getElementById('<%= pplReqUser.ClientID  %>'));

            Trim(document.getElementById('<%= hdnBalanceLeave.ClientID  %>'));

            var reqUser = document.getElementById('<%= pplReqUser.ClientID  %>');

            var hdnWfOrder = document.getElementById('<%= hdnWfOrder.ClientID %>');
            var hdnBalLeave = document.getElementById('<%= hdnBalanceLeave.ClientID %>');

            var travelDt = document.getElementById('<%= dtTravelDt.Controls[0].ClientID %>');
            var reqDt = document.getElementById('<%= dtpDate.Controls[0].ClientID %>');
            var returnDt = document.getElementById('<%= dtReturnDt.Controls[0].ClientID %>');
            var cmnts = document.getElementById('<%= TxtComments.ClientID %>');

            var MyRadio = document.getElementById("<%=rdBtn.ClientID%>");
            var options = MyRadio.getElementsByTagName("input");
            var radVal;
            for (x = 0; x < options.length; ++x) {
                if (options[x].checked) {
                    radVal = x;
                }
            }

            if (querystringval == "New") {

                if (radVal == 1 && isEmpty(reqUser)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = document.getElementById('<%= pplReqUser.ClientID  %>');
                    rval = false;
                }

                else if (fnLeaveOther()) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = document.getElementById("<%=txtLeaveOthers.ClientID%>");
                    rval = false;
                }

                else if (isEmpty(travelDt)) {
                    ErrorMsg = "Fields marked with (*) cannot be left blank";
                    objFocus = travelDt;
                    rval = false;
                }

                else if (!isEmpty(travelDt)) {
                    if (!IsValidDateFormat(travelDt.value)) {
                        ErrorMsg = "Date format should be dd/mm/yyyy !";
                        objFocus = travelDt;
                        rval = false;
                    }
                    else {
                        travelDts = true;
                        if (!PreSaveAction(reqDt, travelDt)) {
                            ErrorMsg = "The Travel Date should be greater than the Current Date";
                            objFocus = travelDt;
                            rval = false;
                        }
                        else {

                            if (isEmpty(returnDt)) {
                                ErrorMsg = "Fields marked with (*) cannot be left blank";
                                objFocus = returnDt;
                                rval = false;
                            }
                            else if (!isEmpty(returnDt)) {

                                if (!IsValidDateFormat(returnDt.value)) {
                                    ErrorMsg = "Date format should be dd/mm/yyyy !";
                                    objFocus = returnDt;
                                    rval = false;
                                }
                                else {
                                    returnDts = true;
                                    if (travelDts == true && returnDts == true) {
                                        if (!PreSaveAction(travelDt, returnDt)) {
                                            ErrorMsg = "The Return Date should be greater than the Travel Date";
                                            objFocus = returnDt;
                                            rval = false;
                                        }
                                        else {
                                            DaysCalculate();
                                            var leaveDay = document.getElementById('<%= txtLeaveDay.ClientID %>');
                                            var item1 = parseInt(hdnBalLeave.value);
                                            var item2 = parseInt(leaveDay.value);
                                            if (!isEmpty(hdnBalLeave)) {
                                                if (item2 > item1) {
                                                    ErrorMsg = "You do not have a required balance Leave";
                                                    objFocus = returnDt;
                                                    rval = false;
                                                }
                                                else {
                                                    if (isEmpty(cmnts)) {
                                                        ErrorMsg = "Fields marked with (*) cannot be left blank";
                                                        objFocus = cmnts;
                                                        rval = false;
                                                    }
                                                    else {
                                                    }
                                                }
                                            }
                                            else {
                                                ErrorMsg = "You do not have a required balance Leave";
                                                objFocus = returnDt;
                                                rval = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                }
            }

            if (rval == false) {
                document.getElementById('<%= lblError.ClientID  %>').style.display = "block";
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = ErrorMsg;
                objFocus.focus();
            }
            else {
                document.getElementById('<%= lblError.ClientID  %>').innerHTML = "";
                document.getElementById('<%= lblError.ClientID  %>').style.display = "none";
            }
            return rval;
        }
        
    </script>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    Leave Request Form
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    Leave Request Form
</asp:Content>
